1
|
|
|
/*jslint |
2
|
|
|
indent: 4 |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
/*global |
6
|
|
|
$, |
7
|
|
|
Cookies, Marker, |
8
|
|
|
trackMarker |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
var Markers = {}; |
12
|
|
|
Markers.m_map = null; |
13
|
|
|
Markers.m_markers = null; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
Markers.init = function (themap) { |
17
|
|
|
'use strict'; |
18
|
|
|
|
19
|
|
|
this.m_map = themap; |
20
|
|
|
this.m_markers = new Array(26 * 10); |
21
|
|
|
|
22
|
|
|
var id; |
23
|
|
|
for (id = 0; id !== this.m_markers.length; id = id + 1) { |
24
|
|
|
this.m_markers[id] = new Marker(this, id); |
25
|
|
|
} |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
Markers.getSize = function () { |
30
|
|
|
'use strict'; |
31
|
|
|
|
32
|
|
|
return this.m_markers.length; |
33
|
|
|
}; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
Markers.getById = function (id) { |
37
|
|
|
'use strict'; |
38
|
|
|
|
39
|
|
|
if (id < 0 || id >= this.m_markers.length) { |
40
|
|
|
return null; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return this.m_markers[id]; |
44
|
|
|
}; |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
Markers.getUsedMarkers = function () { |
48
|
|
|
'use strict'; |
49
|
|
|
|
50
|
|
|
var count = 0; |
51
|
|
|
this.m_markers.map(function (m) { |
52
|
|
|
if (!m.isFree()) { |
53
|
|
|
count = count + 1; |
54
|
|
|
} |
55
|
|
|
}); |
56
|
|
|
return count; |
57
|
|
|
}; |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
Markers.getFreeMarkers = function () { |
61
|
|
|
'use strict'; |
62
|
|
|
|
63
|
|
|
return this.getSize() - this.getUsedMarkers(); |
64
|
|
|
}; |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
Markers.getFreeId = function () { |
68
|
|
|
'use strict'; |
69
|
|
|
|
70
|
|
|
var id; |
71
|
|
|
for (id = 0; id < this.m_markers.length; id = id + 1) { |
72
|
|
|
if (this.m_markers[id].isFree()) { |
73
|
|
|
return id; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
return -1; |
77
|
|
|
}; |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
Markers.getNextUsedId = function (id) { |
81
|
|
|
'use strict'; |
82
|
|
|
|
83
|
|
|
var i; |
84
|
|
|
for (i = id + 1; i < this.m_markers.length; i = i + 1) { |
85
|
|
|
if (!this.m_markers[i].isFree()) { |
86
|
|
|
return i; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
return -1; |
90
|
|
|
}; |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
Markers.removeById = function (id) { |
94
|
|
|
'use strict'; |
95
|
|
|
|
96
|
|
|
if (id >= 0 && id < this.m_markers.length) { |
97
|
|
|
this.m_markers[id].clear(); |
98
|
|
|
} |
99
|
|
|
}; |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
Markers.deleteAll = function () { |
103
|
|
|
'use strict'; |
104
|
|
|
|
105
|
|
|
this.m_markers.map( |
106
|
|
|
function (m) { |
107
|
|
|
m.clear(); |
108
|
|
|
} |
109
|
|
|
); |
110
|
|
|
}; |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
Markers.saveMarkersList = function () { |
114
|
|
|
'use strict'; |
115
|
|
|
|
116
|
|
|
var ids = []; |
117
|
|
|
this.m_markers.map( |
118
|
|
|
function (m) { |
119
|
|
|
if (!m.isFree()) { |
120
|
|
|
ids.push(m.getId()); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
); |
124
|
|
|
Cookies.set('markers', ids.join(":"), {expires: 30}); |
125
|
|
|
}; |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
Markers.toString = function () { |
129
|
|
|
'use strict'; |
130
|
|
|
|
131
|
|
|
var parts = []; |
132
|
|
|
this.m_markers.map( |
133
|
|
|
function (m) { |
134
|
|
|
if (!m.isFree()) { |
135
|
|
|
parts.push(m.toString()); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
); |
139
|
|
|
return parts.join("*"); |
140
|
|
|
}; |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
Markers.update = function () { |
144
|
|
|
'use strict'; |
145
|
|
|
|
146
|
|
|
this.m_markers.map( |
147
|
|
|
function (m) { |
148
|
|
|
m.update(); |
149
|
|
|
} |
150
|
|
|
); |
151
|
|
|
}; |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
Markers.handleMarkerCleared = function () { |
155
|
|
|
'use strict'; |
156
|
|
|
|
157
|
|
|
if (this.getUsedMarkers() === 0) { |
158
|
|
|
$('#btnmarkers2').hide(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
this.saveMarkersList(); |
162
|
|
|
}; |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
Markers.goto = function (id) { |
166
|
|
|
'use strict'; |
167
|
|
|
|
168
|
|
|
trackMarker('goto'); |
169
|
|
|
|
170
|
|
|
var m = this.getById(id); |
171
|
|
|
if (m) { |
172
|
|
|
this.m_map.setCenter(m.getPosition()); |
173
|
|
|
} |
174
|
|
|
}; |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
Markers.center = function (id) { |
178
|
|
|
'use strict'; |
179
|
|
|
|
180
|
|
|
trackMarker('center'); |
181
|
|
|
|
182
|
|
|
var m = this.getById(id); |
183
|
|
|
if (m) { |
184
|
|
|
m.setPosition(this.m_map.getCenter()); |
185
|
|
|
} |
186
|
|
|
}; |
187
|
|
|
|